/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.ProductTempSKUEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class ProductSKUTempMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.selectAll
    
    public List<ProductTempSKUEntity> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_productskutemp where `ytenant_id`=?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new ProductTempSKUEntity());
        return (List<ProductTempSKUEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(ProductTempSKUEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" update dxqyy_productskutemp set `code` = ?, `skuName` = ?, `productId` = ?, `freex1` = ?, `freeidx1` = ?, `free1` = ?, `model` = ?, `modelDescription` = ?, `freeidx1_Name` = ?, `specs` = ?, `specIds` = ?, ");
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getSkuName(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getFreex1(), Types.VARCHAR);
		parameter.addParamWithType(record.getFreeidx1(), Types.VARCHAR);
		parameter.addParamWithType(record.getFree1(), Types.VARCHAR);
		parameter.addParamWithType(record.getMyModel(), Types.VARCHAR);
		parameter.addParamWithType(record.getMyModelDescription(), Types.VARCHAR);
		parameter.addParamWithType(record.getFreeidx1_Name(), Types.VARCHAR);
		parameter.addParamWithType(record.getSpecs(), Types.VARCHAR);
		parameter.addParamWithType(record.getSpecIds(), Types.VARCHAR);
		if (record.getTenant_id() != null && !"".equals(record.getTenant_id())) {
			sqlBuilder.append(" `ytenant_id` = ?, ");
			parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		}
		sqlBuilder.append(" `isSKU` = ? where `id` = ? ");
		parameter.addParamWithType(record.getIsSKU(), Types.INTEGER);
		parameter.addParamWithType(record.getId(), Types.BIGINT);

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_productskutemp where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.deleteByPrimaryKeys
    
    public Integer deleteByPrimaryKeys(Long[] ids) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" delete from dxqyy_productskutemp where ");
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" `id` in ( ");
			int i = 0;
			String separator0 = " , ";
			for (Long id : ids) {
				sqlBuilder.append(" ? ");
				parameter.addParam(id);
				if (i < ids.length - 1) {
					sqlBuilder.append(separator0);
				}
				i++;
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" `id` in ('')");
		}

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.insertBatch
    
    public Integer insertBatch(List<ProductTempSKUEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_productskutemp (`id`, `code`, `skuName`, `productId`, `freex1`, `freeidx1`, `free1`, `model`, `modelDescription`, `freeidx1_Name`, `specs`, `specIds`, `isSKU`,`ytenant_id`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				ProductTempSKUEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getSkuName(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductId(), Types.VARCHAR);
				parameter.addParamWithType(item.getFreex1(), Types.VARCHAR);
				parameter.addParamWithType(item.getFreeidx1(), Types.VARCHAR);
				parameter.addParamWithType(item.getFree1(), Types.VARCHAR);
				parameter.addParamWithType(item.getMyModel(), Types.VARCHAR);
				parameter.addParamWithType(item.getMyModelDescription(), Types.VARCHAR);
				parameter.addParamWithType(item.getFreeidx1_Name(), Types.VARCHAR);
				parameter.addParamWithType(item.getSpecs(), Types.VARCHAR);
				parameter.addParamWithType(item.getSpecIds(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsSKU(), Types.INTEGER);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE code=VALUES(code),skuName=VALUES(skuName),tenant_id=VALUES(tenant_id) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.insert
    
    public int insert(ProductTempSKUEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_productskutemp (`id`, `code`,  `skuName`, `productId`,  `freex1`, `freeidx1`,  `free1`, `model`, `modelDescription`,  `freeidx1_Name`, `specs`,  `specIds`, `isSKU`, `ytenant_id`) values (?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?,  ?, ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getSkuName(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getFreex1(), Types.VARCHAR);
		parameter.addParamWithType(record.getFreeidx1(), Types.VARCHAR);
		parameter.addParamWithType(record.getFree1(), Types.VARCHAR);
		parameter.addParamWithType(record.getMyModel(), Types.VARCHAR);
		parameter.addParamWithType(record.getMyModelDescription(), Types.VARCHAR);
		parameter.addParamWithType(record.getFreeidx1_Name(), Types.VARCHAR);
		parameter.addParamWithType(record.getSpecs(), Types.VARCHAR);
		parameter.addParamWithType(record.getSpecIds(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsSKU(), Types.INTEGER);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.selectById
    
    public ProductTempSKUEntity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_productskutemp where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new ProductTempSKUEntity());
        return (ProductTempSKUEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_productskutemp where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.selectAllByProductIds
    
    public List<ProductTempSKUEntity> selectAllByProductIds(String tenantId, Long[] ids) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from dxqyy_productskutemp where `ytenant_id`=? ");
		parameter.addParam(tenantId);
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" and productId in ( ");
			int i = 0;
			String separator0 = " , ";
			for (Long id : ids) {
				sqlBuilder.append(" ? ");
				parameter.addParam(id);
				if (i < ids.length - 1) {
					sqlBuilder.append(separator0);
				}
				i++;
			}
			sqlBuilder.append(" ) ");
		}

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new ProductTempSKUEntity());
        return (List<ProductTempSKUEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductSKUTempMapper.updateList
    
    public Integer updateList(List<ProductTempSKUEntity> updateList) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		if (CollectionUtil.isNotEmpty(updateList)) {
			String separator0 = " ; ";
			for (int i = 0; i < updateList.size(); i++) {
				ProductTempSKUEntity item = updateList.get(i);
				sqlBuilder.append(" update dxqyy_productskutemp set `code` = ?, `skuName` = ?, `productId` = ?, `freex1` = ?, `freeidx1` = ?, `freeidx1_Name` = ?, `free1` = ?, `model` = ?, `modelDescription` = ?, `specs` = ?, `specIds` = ?, `isSKU` = ? where `id` = ? ");
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getSkuName(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductId(), Types.VARCHAR);
				parameter.addParamWithType(item.getFreex1(), Types.VARCHAR);
				parameter.addParamWithType(item.getFreeidx1(), Types.VARCHAR);
				parameter.addParamWithType(item.getFreeidx1_Name(), Types.VARCHAR);
				parameter.addParamWithType(item.getFree1(), Types.VARCHAR);
				parameter.addParamWithType(item.getMyModel(), Types.VARCHAR);
				parameter.addParamWithType(item.getMyModelDescription(), Types.VARCHAR);
				parameter.addParamWithType(item.getSpecs(), Types.VARCHAR);
				parameter.addParamWithType(item.getSpecIds(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsSKU(), Types.INTEGER);
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				if (i < updateList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

}
